<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Bulletin/classes/PhpFox_ComponentView.class.php, $Author:  $ */



/** Display list bulletins
 *
 * Parameters:
 *  1. oUser (mandatory) - user account object
 *
 * @package module.bulletin
 * @version $Id:
 *   PHPFox Team ()
 */
class PhpFox_Mod_Bulletin_ComponentView extends BaseComponent
{
	function process()
	{

	    $oReq = &App::getRequest();
	    $oSrvBulletin = $this->_oModule->getService('Bulletin');
	    $oSrvAccount = &App::getModuleService('Account', 'Security');
	    $oSrvFriend  = &App::getModuleService('Account', 'Friends');
	    $bIsAdmin = ($oSrvAccount->isAdmin() || $oSrvAccount->isStaff()) ? true : false;

	    $oCurrUser = &$oSrvAccount->getCurrentUser();

	    $sCurrentUser = $oSrvAccount->getCurrentUserLogin();
	    $oTpl = &$this->_oModule->getTemplate();

	    if($oReq->getInt('id'))
	        $aBulletinInfo = $oSrvBulletin->getBulletinById($oReq->getInt('id'));

	    if(empty($aBulletinInfo['id']))
	       App::gotoUrl('public.account.bulletin');

	    if($oSrvBulletin->isNewBoard($aBulletinInfo['id'], $sCurrentUser))
                $oSrvBulletin->setStatusView($aBulletinInfo['id'], $sCurrentUser);

		$iIsFriend = true;
		if (!$bIsAdmin AND App::getUser('user') !=  $aBulletinInfo['user'] AND $oSrvFriend->checkIsFriend(App::getUser('user'), $aBulletinInfo['user']) == 0 )
		{
           	$iIsFriend = false;
        }

        $oTpl->assignSrc(array(
                                'aBulletinInfo'    => !empty($aBulletinInfo) ? $aBulletinInfo : false,
                                'bIsAdmin'         => $bIsAdmin,
                                'bIsOwner'         => ($sCurrentUser == $aBulletinInfo['user']) ? true : false,
                                )
        );
        $oTpl->assign(array(
			                 'sBoxName'     => App::format('bb.board'),
			                 'aErrors'		=> $this->getErrors(),
                             'sUserPicUrl' 	=> App::getParam('user.pic.url'),
                             'aNav'     => !empty($aNav) ? $aNav : false,
                             'iIsFriend' => $iIsFriend,
                             // 'iUserId' => App::getUserDetails($aBulletinInfo['user'],"id"),
			));

		$srcHtml = $oTpl->fetch('View.html');
		return $srcHtml;
	}
}
?>